<%@ taglib prefix="c" uri="/WEB-INF/tlds/hdiv-c.tld"%>
<%@ taglib prefix="form" uri="/WEB-INF/tlds/hdiv-spring-form-3_0_4.tld"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<c:url value="seleccionarMatriz.html" var="seleccionarMatriz"/>
<%@ page contentType="text/form;charset=windows-1252"%>
<script src="javascript/jquery.displaytag-ajax-1.2.js" type="text/javascript"></script>
  <script type="text/javascript">  
    $(function() {
        $('span.pagelinks>a, table#dispTable>thead>tr>th>a').live('click', function(){
            $.get($(this).attr('href'), function(responseText, status, xmlHttpRequest){
                $('#displayTagDiv').html($('#displayTagDiv', responseText).html());
                }
            )            
            return false;
        })
    });
    $(document).ready(function(){                
        $.getJSON("<c:url value='seleccionarMatriz.html'/>", {accion : "searchDesMat" },function(data){
            $("#desMat").autocomplete({source:data});
        });        
        $("form").submit(function(){
            return false;
        });
        $("#desMat").bestupper({
            clear:false
        });
        $("#codSucuHtb").change(function(){ 
            $("#desMat").val("");            
            $.get("<c:url value='seleccionarMatriz.html'/>",{accion:"buscarMatrizBySucursal",codSucuHtb:$("#codSucuHtb").val(),desMat:$("#desMat").val()}, function(responseText, status, xmlHttpRequest){
                $('#displayTagDiv').html($('#displayTagDiv', responseText).html());
                $.getJSON("<c:url value='seleccionarMatriz.html'/>", {accion : "searchDesMat" },function(data){
                    $("#desMat").autocomplete({source:data});
                });
                }
            );
        });
        $("#aceptar").click(function(){ 
            self.close();
        }); 
        $("#mostrar").click(function(){ 
            $.get("<c:url value='seleccionarMatriz.html'/>",{accion:"buscarMatrizBySucursal",codSucuHtb:$("#codSucuHtb").val(),desMat:$("#desMat").val()}, function(responseText, status, xmlHttpRequest){
                $('#displayTagDiv').html($('#displayTagDiv', responseText).html());
                }
            )            
        });
    });
    function setChkMatriz(checkObj){
        var idChkObj = checkObj.checked;
        if(idChkObj){
            $.getJSON("<c:url value='seleccionarMatriz.html'/>", {accion : "selectCodMat",codMat: checkObj.value});
        }else{
            $.getJSON("<c:url value='seleccionarMatriz.html'/>", {accion : "deSssselectCodMat",codMat: checkObj.value});
        }        
    }   
      
    function setChkTodos(checkTodos){
        var booCheckTodos = "Check Object: "+ checkTodos.checked;
        $.get("<c:url value='seleccionarMatriz.html'/>",{accion:"selectTodos",codTodos:checkTodos.checked}, function(responseText, status, xmlHttpRequest){
            $('#displayTagDiv').html($('#displayTagDiv', responseText).html());
            }
        )        
    }
  </script>
<meta http-equiv="Content-Type" content="text/form;charset=windows-1252">

<body>

<form:form modelAttribute="form" name="form" action="#">
<form:hidden path="accion"/>
<form:hidden path="cliente"/>
    <table id="fullheighttable" width="500" align="center">
        <tr>
            <td align="left" valign="top" class="fondo_modal padtop16left21">
                <table>
                    <tr>
                        <td class="verdana11bazul">Sucursal</td>
                        <td>
                            <form:select path="codSucuHtb">
                                <form:option value="0">TODOS</form:option>
                                      <form:options items="${listSucursales}"
                                                    itemValue="codSucursal"
                                                    itemLabel="desSucursal"/>
                            </form:select>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td class="verdana11bazul">Matriz</td>
                        <td>
                            <form:input path="desMat" cssClass="fondo_txtbox258"/>
                        </td>
                        <td>
                            <input type="button" class="boton" id="mostrar" value="Mostrar"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" style="color:red;font-weight:bold;text-align:left;">
                        Lista de Matrices
                        </td>
                    </tr>                    
                    <tr>
                        <td colspan="3">
                        <input type='checkbox' id='chkTodos' onclick='setChkTodos(this)'/> Todos  
                        <div id="displayTagDiv">
                        <c:set var="count" value="0"/>
                        <display:table name="listMatrices" class="its" 
                                       pagesize="5" id="matriz"
                                       requestURI="/seleccionarMatriz.html" >
                            
                            <display:column title="Sel">
                                <c:set var="count" value="${count+1}"/>
                                <input type="checkbox" id="_chk${matriz.codMat}" name="_chk" onclick="setChkMatriz(this);" value="${matriz.codMat}" ${matriz.chkMarca}/>
                            </display:column> 
                            <display:column escapeXml="true" style="width:400px;text-align:left;" property="desMat" title="<font style='text-align:left;'>Descripci&oacute;n</font>"/>
                            <display:column escapeXml="true" style="width:150px;text-align:center;" property="desSucursal" title="Sucursal"/>
                        </display:table>
                        </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">                
                            <input type="button" value="Aceptar" id="aceptar" class="boton"/>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr><td>
            <div id="matrices"></div>
        </td></tr>
    </table>
</form:form>
</body>